package com.sky.web.app;

import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("userOrderController")
@RequestMapping("/user/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 提交订单
     * @param ordersSubmitDTO
     * @return
     */
    @PostMapping("/submit")
    public Result submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        //接收参数
        OrderSubmitVO vo=orderService.submit(ordersSubmitDTO);
        return Result.success(vo);
    }

    /**
     * 历史订单
     * @param page
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping("/historyOrders")
    public Result historyOrder(@RequestParam(defaultValue = "1") Integer page,
                               @RequestParam(defaultValue = "5") Integer pageSize ,
                               Integer status) {
        PageResult pageResult=orderService.page4app(page,pageSize,status);
        return Result.success(pageResult);
    }

    /**
     * 订单详情
     * @return
     */
    @GetMapping("/orderDetail/{orderId}")
    public Result orderDetail(@PathVariable Long orderId){
        //调用service
        OrderVO vo=orderService.orderDetail(orderId);
        return Result.success(vo);

    }


    /**
     *取消订单
     * @param orderId
     * @return
     */
    @PutMapping("/cancel/{orderId}")
    public Result cancel(@PathVariable Long orderId){
        orderService.cancel(orderId);
        return Result.success();

    }

    /**
     * 再来一单
     * @param orderId
     * @return
     */
    @PostMapping("/repetition/{id}")
    public Result repetition(@PathVariable Long orderId){
        orderService.repetition(orderId);
        return Result.success();
    }

    /**
     * 用户催单
     * @param orderId
     * @return
     */
    @GetMapping("/reminder/{orderId}")
    public Result reminder(@PathVariable("orderId") Long orderId) {
        orderService.reminder(orderId);
        return Result.success();
    }
}
